//这里才是真正存放请求函数的地方
import http from "./http.js";
import api from "./api.js";
import axios from "axios";

// 获取轮播图信息
export function getLunbo(data) {
  return axios({
    method: "GET",
    url: api.lunbo,
    params: data,
  });
}
// 获取分类信息
export function getClassify(data) {
  return axios({
    method: "GET",
    url: api.classify,
    params: data,
  });
}
//获取商品列表
export function getGoods(data) {
  return axios({
    method: "GET",
    url: api.goods,
    params: data,
  });
}
//获取单个商品信息
export function getGood(id) {
  return axios({
    method: "GET",
    // url: api.good + "/" + id + "?project_id=255",
    url:`${api.good}/${id}/?project_id=255`,
  });
}
//登陆
export function userLogin(data) {
  return axios({
    method: "POST",
    url: api.login,
    // 请求体的参数应该放到data中
    data,
  });
}
//注册
export function userRegister(data) {
  return axios({
    method: "POST",
    url: api.register,
    // 请求体的参数应该放到data中
    data,
  });
}
//添加购物车信息
export function addCart(data) {
  return http({
    method: "POST",
    url: api.cart,
    data,
  });
}
//获取购物车信息
export function getCart(data) {
  return http({
    method: "GET",
    url: api.cart,
    params: data,
  });
}
//删除购物车信息
export function delCart(id) {
  return http({
    method: "DELETE",
    url: api.cart + "/" + id,
    
  });
}
//更新单条购物车信息
export function putCart(id,data) {
  return http({
    method: "PUT",
    url: api.cart + "/" + id,
    data
  });
}
// 添加订单信息
export function postOrder(data){
  return http({
    method:"POST",
    url:api.order,
    data,
  })
}
// 获取订单列表
export function getOrder(){
  return http({
    method:"GET",
    url:api.order+"?"+"project_id=255",
  })
}
// 删除订单信息
export function delOrder(id){
  return http({
    method:"DELETE",
    url:api.order+"/"+id,
  })
}
// 获取单条订单信息
export function getOneOrder(id){
  return http({
    method:"GET",
    url:api.order+"/"+id,
  })
}
// 更新订单信息
export function putOneOrder(id){
  return http({
    method:"PUT",
    url:api.order,
    id,
  })
}
// 获取所有城市信息
export function getCity(){
  return axios({
    method:"GET",
    url:api.city,
  })
}
// 添加地址
export function postAdress(data){
  return http({
    method:"POST",
    url:api.address,
    data,
  })
}
// 获取地址列表
export function getAddress(){
  return http({
    method:"GET",
    url:api.address,
  })
}
// 更新单条地址信息
export function putAddress(id,data){
  return http({
    method:"PUT",
    url:api.address+"/"+id,
    data,
  })
}
// 删除单条地址信息
export function delAddress(id){
  return http({
    method:"DELETE",
    url:api.address+"/"+id,
   
  })
}
// 设置默认地址信息
export function postDefault(id){
  return http({
    method:"POST",
    url:api.setDefault+"/"+id, 
  })
}
// 获取默认地址信息
export function getDefault(){
  return http({
    method:"GET",
    url:api.default,
  })
}
// 获取搜索商品的信息
export function getSearch(name){
  return http({
    method:"GET",
    url:api.search+"?"+"project_id=255"+"&"+"name=" + name,
  })
}
// 获取头像上传的信息
export function getHeadImg(data){
  return http({
    method:"POST",
    url:api.headimg,
    data,
  })
}
// 获取修改用户信息的信息
export function getChangeUser(id,data){
  return http({
    method:"PUT",
    url:api.user+"/"+id,
    data,
  })
}